<?php

HBase::using('DAL.HPages');
HBase::using('DAL.HPagesModules');
HBase::using('DAL.HModules');
HBase::using('DAL.HModulesInstances');

class HLayout {
	public function loadModulesToPanes($alias, $panename) {			
		// Get Page ID
		$page_id = HPages::getPageIdByAlias($alias);				
		// Get page modules
		$modules = HPages::getModulesByPane($page_id, $panename);
		
		// Render
		if (count($modules) != 0) {
			for ($i = 0; $i < count($modules); $i++) {
				$name = HModules::getModuleNameById($modules[$i]['module_instance_id']);	
				
				// Path to module
				$path = SYSTEM_PATH.SEPARATOR.'modules'.SEPARATOR.$name.SEPARATOR;
				// Module view file
				$view_file = HModulesInstances::getViewFileById($modules[$i]['module_instance_id']);
				// Class name of the module
				$class_name = str_replace('.php','',$view_file);
				// Template file name
				$template_file = $class_name.'.html.php';
				// Require module		
require_once($path.$view_file);
eval("\$_o = new ".$class_name."('".$path.$template_file."');");
			}
		}		
	}
}